﻿<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
    <meta charset="utf-8" />
    <script src="/print/js/html2canvas.js"></script>
</head>
<body>
    <!--条码打印页面-->
    <div class="code-list">
    </div>
    <link rel="stylesheet" href="/print/print.css?v=1.0.5" media="all">
    <script type="text/javascript" src="/print/jquery.min.js"></script>
    <script type="text/javascript" src="/print/qrcode.min.js"></script>
    <script type="text/javascript" src="/print/jquery-barcode.js"></script>
    <script src="/print/jquery.cookie.js"></script>
    <script>
        var barcode_ids;
        var cookie_barcode_ids = $.cookie('cookie_barcode_ids');
        if (!cookie_barcode_ids) {
            barcode_ids = "";
        } else {
            barcode_ids = cookie_barcode_ids;
        }
        console.log(barcode_ids);
        var norm = GetQueryValue("norm");
        var type = GetQueryValue("type");//0--前五个，1--物品标签，2--位置标签
        var v1 = GetQueryValue("v1");
        var v2 = GetQueryValue("v2");
        var v3 = GetQueryValue("v3");
        var v4 = GetQueryValue("v4");
        var v5 = GetQueryValue("v5");
        var v6 = GetQueryValue("v6");
        var v7 = GetQueryValue("v7");
        console.log(v1);
        $(function () {
            var n = parseInt(norm);
            switch (n) {
                case 0:
                    getNCodeList(type,v1, barcode_ids);
                    break;
                case 1:
                    getCodeList(type, v1, v2, v3, v4, v5, v6, v7);
                    break;
                default:
                   
            }
        })
        function GetQueryValue(queryName) {
            var reg = new RegExp("(^|&)" + queryName + "=([^&]*)(&|$)", "i");
            var r = window.location.search.substr(1).match(reg);
            if (r != null) {
                return decodeURI(r[2]);
            } else {
                return null;
            }
        }
        function getCodeList(type,val1, val2, val3, val4, val5, val6, val7) {
            $.ajax({
                url: '/print/data.ashx?oper=getCodeList',
                type: 'get',
                async: true,
                data: {
                    val1: val1,
                    val2: val2,
                    val3: val3,
                    val4: val4,
                    val5: val5,
                    val6: val6,
                    val7: val7
                },
                dataType: 'json'
            }).then(function (res) {
                console.log(res);
                if (res.status == "1") {
                    var result = res.result;
                    if (result.length > 0) {
                        setJson(type, result);
                    }
                    else {
                        $(".code-list").html("未查询到数据");
                    }
                }
                else {
                    layer.msg('系统错误');
                    return false;
                }
            }).fail(function (res) {
                console.log('失败');
                console.log(res.responseText);
            })
        }
        function getNCodeList(type,label, ids) {
            $.ajax({
                url: '/print/data.ashx?oper=getNCodeList',
                type: 'get',
                async: true,
                data: {
                    label: label,
                    ids: ids
                },
                dataType: 'json'
            }).then(function (res) {
                console.log(res);
                if (res.status == "1") {
                    var result = res.result;
                    if (result.length > 0) {
                        setNJson(type, result);
                    }
                    else {
                        $(".code-list").html("未查询到数据");
                    }
                }
                else {
                    layer.msg('系统错误');
                    return false;
                }
            }).fail(function (res) {
                console.log('失败');
                console.log(res.responseText);
            })
        }
        function setJson(type, json) {
            console.log(type)
            var _str = '';
            var n = parseInt(type);
            console.log(n)
            //n = 0;
            switch (n) {
                case 0:
                    //代码块,前五个
                    var result = [];
                    for (var i = 0, len = json.length; i < len; i += 12) {
                        result.push(json.slice(i, i + 12));
                    }
                    console.log(result);
                    _str += '<div class="box2">';
                    $.each(result, function (j, jtem) {
                        _str += '<div class="A4">';
                        $.each(jtem, function (i, item) {
                            _str += '<div class="box" data-index=' + i + '><div class="inbox">'
                                + '<div class="qrcode"><span class="cnaidc" id="' + item.code + '" data-code="' + item.code + '"></span><h5>' + item.code + '</h5></div>'
                                + '<div class="info"><h6 class="name" style="padding-bottom:3mm;padding-top:0.5mm">名称：</h6><span style="padding:6mm 0">规格型号：</span><p style="padding-top:5mm">位置：</p></div></div></div>'
                            if ((i + 1) % 2 == 0) {
                                //_str += '<hr />';
                            }
                        })
                        _str += '</div>';
                    })
                    //$.each(result, function (j, jtem) {
                    //    _str += '<div class="A4">';
                    //    for (var k = 0; k < 4; k++) {
                    //        //_str += '<div class="vertical ver' + (k + 1)+ '"></div>';
                    //    }
                    //    $.each(jtem, function (i, item) {
                    //        _str += '<div class="box" data-index=' + i + '>'
                    //            + '<div class="qrcode"><span class="cnaidc" id="' + item.code + '" data-code="' + item.code + '"></span><h5>' + item.name + '</h5></div></div>'
                    //        if ((i + 1) % 5 == 0) {
                    //            //_str += '<hr />';
                    //        }
                    //    })
                    //    _str += '</div>';
                    //})
                    _str += '</div>';
                    break;
                case 1:
                    //代码块,物品标签
                    var result = [];
                    for (var i = 0, len = json.length; i < len; i += 12) {
                        result.push(json.slice(i, i + 12));
                    }
                    console.log(result);
                    _str += '<div class="box2">';
                    $.each(result, function (j, jtem) {
                        _str += '<div class="A4">';
                        $.each(jtem, function (i, item) {
                            var reg1 = new RegExp("：", "g");
                            var reg2 = new RegExp("，", "g");
                            var reg3 = new RegExp("【", "g");
                            var reg4 = new RegExp("】", "g");
                            var reg5 = new RegExp("〖", "g");
                            var reg6 = new RegExp("〗", "g");
                            var reg7 = new RegExp("&&&", "g");
                            var reg8 = new RegExp("%%%", "g");
                            var reg9 = new RegExp("@@@", "g");
                            var name = item.name, spec = item.spec, model = item.model;
                            name = name.replace(reg1, ":");
                            name = name.replace(reg2, ",");
                            name = name.replace(reg3, "{");
                            name = name.replace(reg4, "}");
                            name = name.replace(reg5, "[");
                            name = name.replace(reg6, "]");
                            name = name.replace(reg7, "/");
                            name = name.replace(reg8, "\\");
                            name = name.replace(reg9, "'");

                            spec = spec.replace(reg1, ":");
                            spec = spec.replace(reg2, ",");
                            spec = spec.replace(reg3, "{");
                            spec = spec.replace(reg4, "}");
                            spec = spec.replace(reg5, "[");
                            spec = spec.replace(reg6, "]");
                            spec = spec.replace(reg7, "/");
                            spec = spec.replace(reg8, "\\");
                            spec = spec.replace(reg9, "'");

                            model = model.replace(reg1, ":");
                            model = model.replace(reg2, ",");
                            model = model.replace(reg3, "{");
                            model = model.replace(reg4, "}");
                            model = model.replace(reg5, "[");
                            model = model.replace(reg6, "]");
                            model = model.replace(reg7, "/");
                            model = model.replace(reg8, "\\");
                            model = model.replace(reg9, "'");
                            _str += '<div class="box" data-index=' + i + '><div class="inbox">'
                                + '<div class="qrcode"><span class="cnaidc" id="' + item.labelcode + '" data-code="' + item.labelcode + '"></span><h5>' + item.labelcode + '</h5></div>'
                                + '<div class="info"><h6 class="name">名称：' + name + '</h6><span>规格型号：' + spec + ' ' + model + '</span><p>位置：' + item.position + '</p></div></div></div>'
                            if ((i + 1) % 2 == 0) {
                                //_str += '<hr />';
                            }
                        })
                        _str += '</div>';
                   })

                    _str += '</div>';
                    break;
                case 2:
                    //代码块,位置标签
                    var result = [];
                    for (var i = 0, len = json.length; i < len; i += 30) {
                        result.push(json.slice(i, i + 30));
                    }
                    console.log(result);
                    _str += '<div class="box1">';
                    $.each(result, function (j, jtem) {
                        _str += '<div class="A4">';
                        for (var k = 0; k < 4; k++) {
                            //_str += '<div class="vertical ver' + (k + 1) + '"></div>';
                        }
                        $.each(jtem, function (i, item) {
                            var reg1 = new RegExp("：", "g");
                            var reg2 = new RegExp("，", "g");
                            var reg3 = new RegExp("【", "g");
                            var reg4 = new RegExp("】", "g");
                            var reg5 = new RegExp("〖", "g");
                            var reg6 = new RegExp("〗", "g");
                            var reg7 = new RegExp("&&&", "g");
                            var reg8 = new RegExp("%%%", "g");
                            var name = item.name;
                            name = name.replace(reg1, ":");
                            name = name.replace(reg2, ",");
                            name = name.replace(reg3, "{");
                            name = name.replace(reg4, "}");
                            name = name.replace(reg5, "[");
                            name = name.replace(reg6, "]");
                            name = name.replace(reg7, "/");
                            name = name.replace(reg8, "\\");
                            _str += '<div class="box" data-index=' + i + '>'
                                + '<div class="qrcode"><h5>' + name + '</h5><span class="cnaidc" id="' + item.code + '" data-code="' + item.code + '"></span></div></div>'
                            if ((i + 1) % 5 == 0) {
                                //_str += '<hr />';
                            }
                        })
                        _str += '</div>';
                    })
                    _str += '</div>';
                    break;
                default:
                    // 默认代码块
            }

            $(".code-list").html(_str);
            //setBarCode();
            setQRCode();
        }
        function setNJson(type, json) {
            var _str = '';
            var n = parseInt(type);
            console.log(n)
            //n = 0;
            switch (n) {
                case 0:
                    //代码块,位置标签
                    var result = [];
                    for (var i = 0, len = json.length; i < len; i += 6) {
                        result.push(json.slice(i, i + 6));
                    }
                    console.log(result);
                    _str += '<div class="box1">';
                    $.each(result, function (j, jtem) {
                        _str += '<div class="A3">';
                        for (var k = 0; k < 4; k++) {
                            //_str += '<div class="vertical ver' + (k + 1) + '"></div>';
                        }
                        $.each(jtem, function (i, item) {
                            var reg1 = new RegExp("：", "g");
                            var reg2 = new RegExp("，", "g");
                            var reg3 = new RegExp("【", "g");
                            var reg4 = new RegExp("】", "g");
                            var reg5 = new RegExp("〖", "g");
                            var reg6 = new RegExp("〗", "g");
                            var reg7 = new RegExp("&&&", "g");
                            var reg8 = new RegExp("%%%", "g");
                            var name = item.name;
                            name = name.replace(reg1, ":");
                            name = name.replace(reg2, ",");
                            name = name.replace(reg3, "{");
                            name = name.replace(reg4, "}");
                            name = name.replace(reg5, "[");
                            name = name.replace(reg6, "]");
                            name = name.replace(reg7, "/");
                            name = name.replace(reg8, "\\");
                            _str += '<div class="box" data-index=' + i + '>'
                                + '<div class="qrcode"><h5>' + name + '</h5><span class="cnaidc" id="' + item.code + '" data-code="' + item.code + '"></span></div></div>'
                            if ((i + 1) % 5 == 0) {
                                //_str += '<hr />';
                            }
                        })
                        _str += '</div>';
                    })
                    _str += '</div>';
                    break;
                case 1:
                    //代码块,物品标签
                    var result = [];
                    for (var i = 0, len = json.length; i < len; i += 2) {
                        result.push(json.slice(i, i + 2));
                    }
                    console.log(result);
                    _str += '<div class="box2">';
                    $.each(result, function (j, jtem) {
                        _str += '<div class="A3">';
                        $.each(jtem, function (i, item) {
                            var reg1 = new RegExp("：", "g");
                            var reg2 = new RegExp("，", "g");
                            var reg3 = new RegExp("【", "g");
                            var reg4 = new RegExp("】", "g");
                            var reg5 = new RegExp("〖", "g");
                            var reg6 = new RegExp("〗", "g");
                            var reg7 = new RegExp("&&&", "g");
                            var reg8 = new RegExp("%%%", "g");
                            var reg9 = new RegExp("@@@", "g");
                            var name = item.name, spec = item.spec, model = item.model;
                            name = name.replace(reg1, ":");
                            name = name.replace(reg2, ",");
                            name = name.replace(reg3, "{");
                            name = name.replace(reg4, "}");
                            name = name.replace(reg5, "[");
                            name = name.replace(reg6, "]");
                            name = name.replace(reg7, "/");
                            name = name.replace(reg8, "\\");
                            name = name.replace(reg9, "'");

                            spec = spec.replace(reg1, ":");
                            spec = spec.replace(reg2, ",");
                            spec = spec.replace(reg3, "{");
                            spec = spec.replace(reg4, "}");
                            spec = spec.replace(reg5, "[");
                            spec = spec.replace(reg6, "]");
                            spec = spec.replace(reg7, "/");
                            spec = spec.replace(reg8, "\\");
                            spec = spec.replace(reg9, "'");

                            model = model.replace(reg1, ":");
                            model = model.replace(reg2, ",");
                            model = model.replace(reg3, "{");
                            model = model.replace(reg4, "}");
                            model = model.replace(reg5, "[");
                            model = model.replace(reg6, "]");
                            model = model.replace(reg7, "/");
                            model = model.replace(reg8, "\\");
                            model = model.replace(reg9, "'");
                            _str += '<div class="box" data-index=' + i + '><div class="inbox">'
                                + '<div class="qrcode"><span class="cnaidc" id="' + item.labelcode + '" data-code="' + item.labelcode + '"></span><h5>' + item.labelcode + '</h5></div>'
                                + '<div class="info"><h6 class="name">名称：' + name + '</h6><span>规格型号：' + spec + ' ' + model + '</span><p>位置：' + item.position + '</p></div></div></div>'
                            if ((i + 1) % 2 == 0) {
                                //_str += '<hr />';
                            }
                        })
                        _str += '</div>';
                    })

                    _str += '</div>';
                    break;
                
                default:
                    // 默认代码块
            }

            $(".code-list").html(_str);
            //setBarCode();
            setQRCode();
        }
        function setBarCode() {
            var settings = {
                output: 'css',
                color: '#000',
                barWidth: 2,
                barHeight: 30,
                displayValue: true,
                fontOptions: "bold",
                fontSize: 16,
                moduleSize: 5,
                addQuietZone: 10
            };
            $.each($(".code-list .box .cnaidc"), function () {
                var _code = $(this).data("code");
                console.log(_code);
                $(this).barcode(_code.toString(), "code128", settings);
            })

            setTimeout(function () {
                window.print();
            }, 20)

        }
        function setQRCode() {
            $.each($(".code-list .box .cnaidc"), function () {
                var _code = $(this).data("code");
                if (!_code) {
                    return false;
                } else {
                    new QRCode(document.getElementById(_code), _code);
                }
            })
            //generateImg();//--生成图片
            setTimeout(function () {
                //window.print();
            }, 20)
        }
        function generateImg() {
            $.each($(".code-list .box"), function () {
                html2canvas($(this)).then(function (canvas) { document.body.appendChild(canvas); });
            })
            setTimeout(function () {
                //window.print();
            }, 20)
        }
    </script>
</body>
</html>
